﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OleDb;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class index : System.Web.UI.Page
{
    public string bh1; public string bh2;
    public string bh3; public string bh4;
    public string bh5; public string bh6;
    public string bh7; public string bh8;
    public string bh9; public string url1;
    public string url2; public string url3;
    public string url4; public string url5;
    public string url6; public string url7;
    public string url8; public string url9;   
    protected void Page_Load(object sender, EventArgs e)
    {
        rpt2();
        rpTest.DataSource = pds();
        rpTest.DataBind();
        rpTest1.DataSource = pds1();
        rpTest1.DataBind();
    }
    protected void rpt2()
    {
        OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0 ;Data Source=|DataDirectory|\\web.mdb");
        string sqlstr = "select * from ty_teacher";
        OleDbDataAdapter myda = new OleDbDataAdapter(sqlstr, con);
        DataSet myds = new DataSet();
        con.Open();
        myda.Fill(myds, "ty_teacher");
        bh1 = myds.Tables[0].Rows[4]["id"].ToString();
        bh2 = myds.Tables[0].Rows[3]["id"].ToString();
        bh3 = myds.Tables[0].Rows[0]["id"].ToString();
        bh4 = myds.Tables[0].Rows[1]["id"].ToString();
        bh5 = myds.Tables[0].Rows[5]["id"].ToString();
        bh6 = myds.Tables[0].Rows[8]["id"].ToString();
        bh7 = myds.Tables[0].Rows[7]["id"].ToString();
        bh8 = myds.Tables[0].Rows[2]["id"].ToString();
        bh9 = myds.Tables[0].Rows[6]["id"].ToString();
        url1 = myds.Tables[0].Rows[4]["ty_pic"].ToString();
        url2 = myds.Tables[0].Rows[3]["ty_pic"].ToString();
        url3 = myds.Tables[0].Rows[0]["ty_pic"].ToString();
        url4 = myds.Tables[0].Rows[1]["ty_pic"].ToString();
        url5 = myds.Tables[0].Rows[5]["ty_pic"].ToString();
        url6 = myds.Tables[0].Rows[8]["ty_pic"].ToString();
        url7 = myds.Tables[0].Rows[7]["ty_pic"].ToString();
        url8 = myds.Tables[0].Rows[2]["ty_pic"].ToString();
        url9 = myds.Tables[0].Rows[6]["ty_pic"].ToString();
        con.Close();

    }
    protected PagedDataSource pds()
    {
        OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0 ;Data Source=|DataDirectory|\\web.mdb");
        con.Open();
        OleDbCommand cmd = new OleDbCommand("select * from news where shenhe='已审核'and lanmu='网站公告' order by id desc", con);
        OleDbDataAdapter sda = new OleDbDataAdapter();
        sda.SelectCommand = cmd;
        DataSet ds = new DataSet();
        sda.Fill(ds, "news");
        PagedDataSource pds = new PagedDataSource();
        pds.DataSource = ds.Tables["news"].DefaultView;//必须设为DefaultView,不能设置成Table
        pds.AllowPaging = true;
        pds.PageSize = 7;
        pds.CurrentPageIndex = Convert.ToInt32(Request.QueryString["page"]);
        con.Close();
        return pds;
    }
    protected void rpTest_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Footer)//页脚绑定时
        {
            Label lblCurrentPage = (Label)e.Item.FindControl("lblCurrentPage");
            Label lblPageCount = (Label)e.Item.FindControl("lblPageCount");
            HyperLink hlFirst = (HyperLink)e.Item.FindControl("hlFirst");
            HyperLink hlPrevious = (HyperLink)e.Item.FindControl("hlPrevious");
            HyperLink hlNext = (HyperLink)e.Item.FindControl("hlNext");
            HyperLink hlLast = (HyperLink)e.Item.FindControl("hlLast");
            DropDownList ddlJumpPage = (DropDownList)e.Item.FindControl("ddlJumpPage");
            int pagecount = pds().PageCount;
            int currentpage = pds().CurrentPageIndex;
            if (currentpage <= 0)
            {
                hlFirst.Enabled = false;
                hlPrevious.Enabled = false;
                hlNext.Enabled = true;
                hlLast.Enabled = true;
            }
            else
            {
                hlPrevious.NavigateUrl = "index.aspx";
            }
            if (currentpage >= pagecount - 1)
            {
                hlFirst.Enabled = true;
                hlPrevious.Enabled = true;
                hlNext.Enabled = false;
                hlLast.Enabled = false;
            }
            else
            {
                hlNext.NavigateUrl = "?page=" + (currentpage + 1);
            }
            hlFirst.NavigateUrl = "?page=0";
            hlLast.NavigateUrl = "?page=" + (pagecount - 1);
            lblCurrentPage.Text = (currentpage + 1).ToString();
            lblPageCount.Text = pagecount.ToString();
        }

    }
    protected PagedDataSource pds1()
    {
        OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0 ;Data Source=|DataDirectory|\\web.mdb");
        con.Open();
        OleDbCommand cmd = new OleDbCommand("select * from news where shenhe='已审核'and lanmu='学习资源' order by id desc", con);
        OleDbDataAdapter sda = new OleDbDataAdapter();
        sda.SelectCommand = cmd;
        DataSet ds = new DataSet();
        sda.Fill(ds, "news");
        PagedDataSource pds1 = new PagedDataSource();
        pds1.DataSource = ds.Tables["news"].DefaultView;//必须设为DefaultView,不能设置成Table
        pds1.AllowPaging = true;
        pds1.PageSize = 7;
        pds1.CurrentPageIndex = Convert.ToInt32(Request.QueryString["page"]);
        con.Close();
        return pds1;

    }
    protected void rpTest1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Footer)//页脚绑定时
        {
            Label lblCurrentPage = (Label)e.Item.FindControl("lblCurrentPage");
            Label lblPageCount = (Label)e.Item.FindControl("lblPageCount");
            HyperLink hlFirst = (HyperLink)e.Item.FindControl("hlFirst");
            HyperLink hlPrevious = (HyperLink)e.Item.FindControl("hlPrevious");
            HyperLink hlNext = (HyperLink)e.Item.FindControl("hlNext");
            HyperLink hlLast = (HyperLink)e.Item.FindControl("hlLast");
            DropDownList ddlJumpPage = (DropDownList)e.Item.FindControl("ddlJumpPage");
            int pagecount = pds1().PageCount;
            int currentpage = pds1().CurrentPageIndex;
            if (currentpage <= 0)
            {
                hlFirst.Enabled = false;
                hlPrevious.Enabled = false;
                hlNext.Enabled = true;
                hlLast.Enabled = true;
            }
            else
            {
                hlPrevious.NavigateUrl = "?page=" + (currentpage - 1);
            }
            if (currentpage >= pagecount - 1)
            {
                hlFirst.Enabled = true;
                hlPrevious.Enabled = true;
                hlNext.Enabled = false;
                hlLast.Enabled = false;
            }
            else
            {
                hlNext.NavigateUrl = "?page=" + (currentpage + 1);
            }
            hlFirst.NavigateUrl = "?page=0";
            hlLast.NavigateUrl = "?page=" + (pagecount - 1);
            lblCurrentPage.Text = (currentpage + 1).ToString();
            lblPageCount.Text = pagecount.ToString();
        }
    }
}